<template>
  <div class="item">
    <div class="logo">
      <img src="	https://res.ztemall.com/m/static/images/appicon.png" alt="" />
      <div class="title">登录中兴商城</div>
    </div>
    <div v-if="changeShow">
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="username"
          placeholder="手机号码"
          :rules="[{ required: true }]"
        />
        <!--小眼睛 -->
        <van-icon name="eye-o" size="25px" @click="changeType" :color="color" />

        <!-- 忘记密码 -->
        <p>忘记密码</p>
        <!-- 通过 validator 进行函数校验 -->
        <van-field
          v-model="password"
          :type="TYPE"
          name="password"
          placeholder="密码"
          :rules="[{ required: true }]"
        />

        <van-field
          v-model="captcha"
          name="captcha"
          placeholder="请输入图形验证"
          :rules="[{ required: true }]"
        />
        <!-- 验证码 -->
        <captcha ref="captcha" />

        <div style="margin: 16px">
          <van-button
            round
            block
            type="info"
            native-type="submit"
            color="red"
            style="width: 325px; margin: auto"
            >登录</van-button
          >
        </div>
      </van-form>
    </div>
    <!-- 短信登录 -->
    <div v-if="!changeShow">
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="username"
          placeholder="手机号码"
          :rules="[{ required: true }]"
        />
        <!--小眼睛 -->
        <!-- <van-icon name="eye-o" size="25px" @click="changeType" :color="color" /> -->

        <van-field
          v-model="captcha"
          name="captcha"
          placeholder="请输入图形验证"
          :rules="[{ required: true }]"
        />
        <!-- 验证码 -->
        <captcha ref="captcha" :class="{ cap: true }" />

        <!-- 通过 validator 进行函数校验 -->
        <!-- 获取验证码 -->
        <p class="note">获取验证码</p>
        <van-field
          v-model="password"
          :type="TYPE"
          name="note"
          placeholder="请输入短信验证码"
          :rules="[{ required: true }]"
        />

        <div style="margin: 16px">
          <van-button
            round
            block
            type="info"
            native-type="submit"
            color="red"
            style="width: 325px; margin: auto"
            >登录</van-button
          >
        </div>
      </van-form>
    </div>
    <div class="login-btn-other-pg">
      <div @click="shangeLogin">{{ login }}</div>
      <div @click="$router.push('/register')">新用户注册</div>
    </div>
    <div class="login-type-area">
      <div class="login-type">
        <div></div>
        <div>其他登录方式</div>
        <div></div>
      </div>
      <div class="login-type-line">
        <div class="zhanghao">
          <van-icon name="friends-o" size="40px" color="skyblue" />
          <div style="margin-top: 5px">中兴帐号</div>
        </div>
        <div class="zhanghao">
          <van-icon name="setting-o" size="40px" color="skyblue" />
          <div style="margin-top: 5px">员工登录</div>
        </div>
      </div>
      <div class="but">
        <div v-if="check" @click="changeCheck"></div>
        <div v-if="!check" @click="changeCheck" class="active">
          <van-icon name="success" color="white" style="margin-left: 2px" />
        </div>
        <div>
          已阅读并同意<span style="color: #079efb">《中兴商城隐私政策》</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Form } from "vant";
import { Field, Button, Toast, Icon } from "vant";
import Captcha from "@/components/Captcha.vue";
import url from "@/config/url";
import { Col, Row } from "vant";

Vue.use(Col);
Vue.use(Row);
Vue.use(Toast);
Vue.use(Button);
Vue.use(Form);
Vue.use(Field);
Vue.use(Icon);

export default {
  components: { Captcha },
  data() {
    return {
      note: "",
      username: "",
      password: "",
      captcha: "",
      Type: true,
      check: false,
      cap: false,
      TYPE: "password",
      color: "",
      changeShow: true,
      login: "账号密码登录",
    };
  },
  methods: {
    onSubmit(values) {
      // console.log(this.$refs.captcha.key);
      // console.log("submit", values);
      const key = this.$refs.captcha.key;
      const { username, password, captcha } = values;
      if (this.check === true) {
        Toast("请先确认已阅读并同意中兴商城隐私政策");
      } else {
        this.$http
          .post(url.login, { username, password, captcha, key })
          .then((res) => {
            // console.log(res);
          });
      }
    },
    changeType() {
      this.Type = !this.Type;
      this.TYPE = this.Type ? "password" : "text";
      this.color = this.Type ? "" : "skyblue";
    },
    changeCheck() {
      this.check = !this.check;
    },
    shangeLogin() {
      this.changeShow = !this.changeShow;
      this.login = this.changeShow ? "短信验证码登录" : "账号密码登录";
      this.cap = !this.cap;
    },
  },
  created() {
    this.$store.commit("changeFooter");
  },
  beforeDestroy() {
    this.$store.commit("changeFooter");
  },
  mounted() {
    if ((this.check = true)) {
      console.log(1);
    }
  },
};
</script>

<style lang="scss" scoped>
.item {
  overflow: hidden;
  position: relative;
  width: 100%;
  .logo {
    margin-top: 25px;
    text-align: center;
    font-size: 16px;
    > div {
      margin-top: 12px;
    }
    img {
      width: 62.53px;
      height: 62.53px;
    }
  }

  .van-cell {
    border-radius: 44px;
    width: 325px;
    box-sizing: border-box;
    margin: 20px auto;
    background: #f4f4f4;
    position: relative;
  }
  .van-icon-eye-o {
    position: absolute;
    top: 217px;
    right: 112px;
    z-index: 111;
  }
  p {
    position: absolute;
    top: 218px;
    right: 40px;
    font-size: 16px;
    z-index: 111;
  }
  .captcha {
    position: absolute;
    top: 278px;
    right: 50px;
    box-sizing: box;
  }
  .cap {
    position: absolute;
    top: 215px !important ;
  }
  .login-btn-other-pg {
    width: 325px;
    height: 54px;
    margin: 0 25px 11.5px;
    display: flex;
    justify-content: space-between;
    font-size: 15px;
    color: #1e1e1e;
    cursor: pointer;
  }
  .login-type-area {
    margin-bottom: 0.85333rem;
    .login-type {
      width: 325px;
      height: 33px;
      margin: 0 25px;
      display: flex;
      justify-content: space-evenly;
      align-items: center;

      > div:nth-child(1) {
        width: 100px;
        height: 0.5px;
        background: rgba(0, 0, 0, 0.14);
      }
      > div:nth-child(2) {
        width: 75px;
        height: 20px;
        font-size: 12px;
        text-align: center;
        line-height: 20px;
      }
      > div:nth-child(3) {
        width: 100px;
        height: 0.5px;
        background: rgba(0, 0, 0, 0.14);
      }
    }
    .login-type-line {
      display: flex;
      width: 325px;
      height: 105px;
      margin: 0 25px;
      align-items: center;
      justify-content: space-around;
      margin: auto;

      font-size: 12px;
      .zhanghao {
        width: 50px;
        height: 67px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
      }
    }
    .but {
      display: flex;
      justify-content: center;
      align-items: center;
      > div:nth-child(1) {
        width: 20px;
        height: 20px;
        margin-right: 5px;
        border: solid 0.064rem rgba(0, 0, 0, 0.44);
        border-radius: 100%;
      }
      width: 250px;
      height: 20px;
      margin: auto;
    }
  }
  .note {
    position: absolute;
    top: 280px;
  }
}
.active {
  border: solid 0.064rem #079efb;
  background: #079efb;
}
</style>
